fix potential memory leaks. (#365)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 30 May 2019 21:10:53 +0000 (15:10 -0600)
committerGitHub <noreply@github.com>
Thu, 30 May 2019 21:10:53 +0000 (15:10 -0600)
* fix potential memory leaks.

* fix more memory leaks.

A method to find these is to add -DQT_ASCII_CAST_WARNINGS and
then look for xstrdup in the warnings.

* a few cleanups clazy caught.

g7towin.cc
gdb.cc
html.cc
navilink.cc
ozi.cc
reference/gc/GCGCA8_logs~html.txt [new file with mode: 0644]
testo.d/text.test
tmpro.cc
xcsv.cc

index ac1c15d9c7f034d65ef0c431169f3644cff5d198..1e575cb1ec2af1fc3c003b1719383561d40249b6 100644 (file)
@@ -510,7 +510,7 @@ data_read()
         break;
 
       case 'L':
-        waypt_add_url(wpt, xstrdup(cdata), nullptr);
+        waypt_add_url(wpt, cdata, nullptr);
         break;
 
       default:
diff --git a/gdb.cc b/gdb.cc
index 9e948136a63b1b0ab41e1a338c58a936a850db0f..5b1f95f0c461ba0fe4dcd31e4906ff498de4c51b 100644 (file)
--- a/gdb.cc
+++ b/gdb.cc
@@ -394,7 +394,7 @@ gdb_write_cstr_list(const char* str)
 static void
 gdb_write_cstr_list(const QString& str)
 {
-  return gdb_write_cstr_list(CSTRc(str));
+  gdb_write_cstr_list(CSTRc(str));
 }
 
 static void
diff --git a/html.cc b/html.cc
index 38df26bf2e4c2867ea8a6b18bdba1b1e68a60328..144180ee4935f69e7fc2a82f9956061995ddc324 100644 (file)
--- a/html.cc
+++ b/html.cc
@@ -215,11 +215,12 @@ html_disp(const Waypoint* wpt)
         if (html_encrypt && encoded) {
           s = rot13(logpart->cdata);
         } else {
-          s = xstrdup(logpart->cdata);
+          s = logpart->cdata;
         }
 
-        QString t = html_entitize(s);
+        char* t = html_entitize(s);
         gbfputs(t, file_out);
+        xfree(t);
       }
 
       gbfprintf(file_out, "</p>\n");
index 6f3f43155da53a3173f4c579eec78caa4be7891d..b7df0c1b31f253b43f32e198fd80ad07f1d30d1b 100644 (file)
@@ -660,7 +660,7 @@ serial_read_routes(Waypoint** waypts)
 
     route_head*    route = route_head_alloc();
     route->rte_num = routedata[2];
-    route->rte_name = xstrdup((char*)routedata + 4);
+    route->rte_name = (char*)routedata + 4;
     route_add_head(route);
 
     for (int sr = 0; sr < MAX_SUBROUTES; sr++) {
diff --git a/ozi.cc b/ozi.cc
index 964e4ab8d0506a348b56fecfd195589bcfc6a668..e5f3d1a1d6d860b3bbd367e733a7f0f9af8ef4b1 100644 (file)
--- a/ozi.cc
+++ b/ozi.cc
@@ -903,7 +903,7 @@ ozi_waypt_pr(const Waypoint* wpt)
       }
     } else {
       /* no description available */
-      shortname = xstrdup("");
+      shortname = "";
     }
   } else {
     shortname = csv_stringclean(wpt->shortname, BADCHARS);
@@ -912,7 +912,7 @@ ozi_waypt_pr(const Waypoint* wpt)
     if (!shortname.isEmpty()) {
       description = csv_stringclean(shortname, BADCHARS);
     } else {
-      description = xstrdup("");
+      description = "";
     }
   } else {
     description = csv_stringclean(wpt->description, BADCHARS);
diff --git a/reference/gc/GCGCA8_logs~html.txt b/reference/gc/GCGCA8_logs~html.txt
new file mode 100644 (file)
index 0000000..e5bac5a
--- /dev/null
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <title>GPSBabel HTML Output</title>
+ <style>
+  p.gpsbabelwaypoint { font-size: 120%; font-weight: bold }
+ </style>
+</head>
+<body>
+<p class="index">
+<a href="#GCGCA8">GCGCA8 - Oozy rat in a sanitary zoo</a><br>
+</p>
+
+<a name="GCGCA8"><hr></a>
+<table width="100%">
+<tr><td><p class="gpsbabelwaypoint">GCGCA8 - N35&deg;55.300 W86&deg;51.700 (16S 512480 3975269)<br>
+<a href="http://www.geocaching.com/seek/cache_details.aspx?guid=cda94cd6-d657-49bd-8e7e-0031ef1b2613">Oozy rat in a sanitary zoo</a> by robertlipe</p></td>
+<td align="right"><p class="gpsbabelcacheinfo">3 / 2<br>
+Unknown Cache / Unknown</p></td></tr>
+<tr><td colspan="2"><p class="gpsbabeldescshort">The cache is not at the coordinates above.   These coords will get you to the correct park and within 1/2 mile of the cache.  The cache is within 35 feet of the trail.   It is not handicapped accessible.   It is a nice walk in the woods that is practical for all ages.  There is no space in the container for trading items.   You should bring a writing stick and bug spray is recommended.</p>
+<p class="gpsbabeldesclong">So if the cache isn't at the above coordinates, where is it?  
+
+<ul>
+
+<li>Too bad I hid a boot
+<li>Too hot to hoot
+<li>Never odd or even
+<li>Do geese see God?
+<li>"Do nine men interpret?" "Nine men," I nod
+<li>Rats live on no evil star
+<li>Go hang a salami, I'm a lasagna hog
+</ul>
+
+Now that it's intuitively obvious to even the most casual observer where the cache is, turn on your geo-mojo and go find it.
+<br>
+<img SRC="http://www.mtgc.org/mtgc_member-banner.gif" WIDTH="500" HEIGHT="40" ALT="Member of Middle Tennessee GeoCachers Club [www.mtgc.org]" BORDER="0"></a></p></p>
+<p class="gpsbabelhint"><strong>Hint:</strong> There Is No Hint</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Found it</span> by <span class="gpsbabellogfinder">littlepod</span> on <span class="gpsbabellogdate">2005-07-03</span><br>
+Enjoyed the puzzle. We seemed to be about 50ft off though. TFTC.</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Write note</span> by <span class="gpsbabellogfinder">robertlipe</span> on <span class="gpsbabellogdate">2005-04-29</span><br>
+TB Drop to show he's hanging out in Nashville until we blast off for Geowoodstock in a few weeks.</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Found it</span> by <span class="gpsbabellogfinder">Big Bumblebee</span> on <span class="gpsbabellogdate">2005-04-18</span><br>
+Found it a while ago.  Thanks.</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Write note</span> by <span class="gpsbabellogfinder">robertlipe</span> on <span class="gpsbabellogdate">2005-03-27</span><br>
+I had to renew my permit with the CDC and in doing so, I trolled out here verified that the infectious ooze is fully within specification and industry accepted tolerance.   Ooze On!</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Found it</span> by <span class="gpsbabellogfinder">Virtual Babe</span> on <span class="gpsbabellogdate">2004-12-27</span><br>
+This was a great cache, however on this day I considered it a FIFM cache (Fun, Invigorating, Frustrating and Maddening), especially when the cache was not replaced in the proper spot by the previous cacher!  Thanks anyway!!</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Write note</span> by <span class="gpsbabellogfinder">robertlipe</span> on <span class="gpsbabellogdate">2004-01-12</span><br>
+I got a complaint from the CDC about oozy rat this weekend.     I went out tonight in the dark and verified that the infectious ooze is fully within specification and industry accepted tolerance. (Although I realize now I did misstate the cache container to the reporting officer when confronted.   It's, uuuuh, smaller than I said.)</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Write note</span> by <span class="gpsbabellogfinder">robertlipe</span> on <span class="gpsbabellogdate">2003-10-04</span><br>
+In the expectation that this cache will get some traffic in the next 48 hours, Ryan and I checked it earlier today.   The Rat is Oozing just as we planned it.</p>
+<p class="gpsbabellog">
+<span class="gpsbabellogtype">Write note</span> by <span class="gpsbabellogfinder">robertlipe</span> on <span class="gpsbabellogdate">2003-07-03</span><br>
+It won't earn him a smiley face, but I've confirmed that rickrich would have indeed sunk the battleship!      Thanx for playing. You get a copy of the home game and some rice-a-roni...</p>
+</td></tr></table>
+</body></html>
\ No newline at end of file
index 71ce40ebb9206bd0630e48c752d6650937bbcfb2..df5bbbc553704052e9d3901cc79517cbda6e6945 100644 (file)
@@ -7,3 +7,6 @@ gpsbabel -i gpx -f ${REFERENCE}/gc/GCGCA8.gpx \
 compare ${REFERENCE}/gc/GCGCA8~text.txt ${TMPDIR}/gc.txt
 compare ${REFERENCE}/gc/GCGCA8~text-encoded.txt ${TMPDIR}/gc-encoded.txt
 compare ${REFERENCE}/gc/GCGCA8~html.txt ${TMPDIR}/gc.html
+
+gpsbabel -i gpx -f ${REFERENCE}/gc/GCGCA8.gpx -o html,logs -F ${TMPDIR}/gc_logs.html
+compare ${REFERENCE}/gc/GCGCA8_logs~html.txt ${TMPDIR}/gc_logs.html
index e18607f4d7e643198c69dfb1ada976dccb16a131..b968e49538ffe5a61084cf6756c67ab8004c97f3 100644 (file)
--- a/tmpro.cc
+++ b/tmpro.cc
@@ -182,7 +182,7 @@ tmpro_waypt_pr(const Waypoint* wpt)
       }
     } else {
       /* no description available */
-      shortname = xstrdup("");
+      shortname = "";
     }
   } else {
     shortname = csv_stringclean(wpt->shortname, ",\"");
@@ -192,7 +192,7 @@ tmpro_waypt_pr(const Waypoint* wpt)
     if (!shortname.isEmpty()) {
       description = csv_stringclean(shortname, ",\"");
     } else {
-      description = xstrdup("");
+      description = "";
     }
   } else {
     description = csv_stringclean(wpt->description, ",\"");
diff --git a/xcsv.cc b/xcsv.cc
index 2526be075b37d8c3f790aea00b65e9ade346e2a2..1d6dbb19e6ae000185ec5f19fedf620716a6f042 100644 (file)
--- a/xcsv.cc
+++ b/xcsv.cc
@@ -180,9 +180,6 @@ typedef enum {
 /* obligatory global struct                                                 */
 /****************************************************************************/
 
-extern char* xcsv_urlbase;
-extern char* prefer_shortnames;
-
 XcsvFile xcsv_file;
 static double pathdist = 0;
 static double oldlon = 999;
@@ -209,8 +206,8 @@ static char* snlenopt = nullptr;
 static char* snwhiteopt = nullptr;
 static char* snupperopt = nullptr;
 static char* snuniqueopt = nullptr;
-char* prefer_shortnames = nullptr;
-char* xcsv_urlbase = nullptr;
+static char* prefer_shortnames = nullptr;
+static char* xcsv_urlbase = nullptr;
 static char* opt_datum;
 
 static const char* intstylebuf = nullptr;